import React, { Component } from 'react';
import "./Login.scss"
import * as service from "../api/index";

class Login extends Component {
    constructor(props) {
        super(props);
        this.state = {
            phone: '',
            pass: ''
        }
    }
    handleChange(e) {
        this.setState({ [e.target.name]: e.target.value })
        // console.log(this.state.pass,this.state.phone);
    }
    async login() {
        if (this.state.pass && this.state.phone) {
            var res = await service.user_login({ phone: this.state.phone, pass: this.state.pass });
            console.log(res);
        }else{
            console.log('请输入用户信息');
        }
    }
    render() {
        return (
            <div className='login'>
                <div className="logo"></div>
                <div className="box">
                    <input
                        type="text"
                        name='phone'
                        value={this.state.phone}
                        onChange={(e) => { this.handleChange(e) }}
                        placeholder='请输入用户名'
                    />
                    <input
                        type="password"
                        name='pass'
                        value={this.state.pass}
                        onChange={(e) => { this.handleChange(e) }}
                        placeholder='请输入密码'
                    />
                    <button onClick={() => { this.login() }}>登录</button>
                    <span><a href="">注册</a></span>
                </div>
            </div>
        );
    }
}

export default Login;